package com.jiutong.meipenggang.ui.activitys;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;

import com.gyf.barlibrary.ImmersionBar;
import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.utils.SpConfig;


/**
 * create for 启动页 判断是否进入引导页还是主页
 * Created by Veken
 */
public class IndexActivity extends AppCompatActivity {

    /**
     * 是否退出APP后重新启动
     */
    private boolean isFirstLoading = false;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //禁止横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    /**
     * 判断是否第一次进入，是的话进入引导页。
     */
    private void init() {
        boolean isFirstUse = SpConfig.getInstance().getBool(
                Constants.IS_FIRST_USE_BOOLEAN, true);
        if (isFirstUse) {
            startActivity(new Intent(IndexActivity.this, GuideActivity.class));
            IndexActivity.this.finish();

        } else {
            if (!isFirstLoading) {
                isFirstLoading = true;
                entryMain();
            }
        }
    }

    /**
     * 进入主界面
     */
    private void entryMain() {
        startActivity(new Intent(IndexActivity.this, MainActivity.class));
        IndexActivity.this.finish();
    }
}
